package com.sky.controller.admin;



import com.sky.constant.MessageConstant;
import com.sky.result.Result;
import com.sky.utils.MinioUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/admin/common")
@Slf4j
@Api(tags = "公共类控制")
public class CommonController {

    @Autowired
    private MinioUtil minioUtil;

    @PostMapping("/upload")
    @ApiOperation("上传文件")
    public Result<String> upLoad(MultipartFile file){
        log.info("从前端传过来的multipartFile为：{},文件名字为：{}",file,file.getName());
        try {
            String photoUrl = minioUtil.upload(file);
            log.info("最后生成的photourl为：{}",photoUrl);
            return Result.success(photoUrl);
        } catch (Exception e) {
            log.error("存放图片报错：{}",e.getMessage());

        }
        return Result.error(MessageConstant.UPLOAD_FAILED);

    }

}
